import random
from pathlib import Path
import shutil
file=Path('H:/a/b/c/d')
file.mkdir(parents=True,exist_ok=True)
# for i in file.parents(len(file.parents -1)):
#     print(i)
def pro_file():
    for i in file.parents:
        if i ==Path('H:/'):
            [Path(file / ''.join(random.choices('abcdefghijklmnopqrstuvwxyz',k=4))).touch() for _ in range(0, 50)]
        else:
            [Path(i / ''.join(random.choices('abcdefghijklmnopqrstuvwxyz', k=4))).touch() for _ in range(0,50)]

pro_file()

def fn(src,names):
    se=set()
    for name in names:
        print(type(name),name)
        if name =='b':
            se.add(name)
        elif name[0] in {'a', 'b', 'c','d','e', 'f', 'g','h','i', 'j', 'k','l','m', 'n', 'o','p','q', 'r', 's','t','u','v','w'}:
            se.add(name)

    print(se-{'b'}-{'c'}-{'d'})
    return (se-{'b'}-{'c'}-{'d'})
##########方法1#############
#ignore = lambda src, names: {name for name in names if name[0] in {'x', 'y', 'z'}}  #方法2
    #return {name for name in names if name[0] in {'a', 'b', 'c','d','e', 'f', 'g','h','i', 'j', 'k','l','m', 'n', 'o','p','q', 'r', 's','t','u','v','w'}}#方法3


shutil.copytree('H:/a','H:/dst',ignore=fn)


# ignore这里可以优化一下












